<?php
class Career extends ORDataObject {
	var	$career_id	=	'';
	var	$vi_name	=	'';
	var	$en_name	=	'';
	var	$auto_suggest_code 	=	'';
	//TODO: add 'disable' field -- ntmdung
	var $disable	=	'';
	
	const JOBLESS = 0;
	
	var	$_table	=	'career';
	var	$_key	=	'career_id';
	var $_internalName = 'Career';
	
	public function Career(){
		parent::ORDataObject();
	}
	
	public function setup($id=0){
		$this->set('id',$id);
		if($id > 0){
			$this->populate();
		}
	}
	
	public function populate(){
		parent::populate('career_id');
	}
	
	public function getCareerList(){
		$field	=	L10nHelper::getLocale();
		$field  =   L10nHelper::changeField($field, "name");
		$ds		=	& new Datasource_sql();
		$sql	=	array(
			'cols'		=>	"$this->_key as id,$field as name, disable, auto_suggest_code",
			'from'		=>	"$this->_table",
			'orderby' 	=> 'auto_suggest_code'
		);
		$ds->setup($this->_db, $sql);
		$result = $ds->toArray();
		return $result;
	}
	
	public function getCareerListForSelect(){
		$field	=	L10nHelper::getLocale();
		$field  =   L10nHelper::changeField($field, "name");
		$ds		=	& new Datasource_sql();
		$sql	=	array(
			'cols'		=>	"$this->_key AS id,$field AS name",
			'from'		=>	"$this->_table",
			'where' 	=> 'disable = 0',
			'orderby' 	=> 'name'
		);
		$ds->setup($this->_db, $sql);
		return $ds->toArray('id', 'name');
	}

    public function getCareerListAutoSuggest(){
        $field  =   L10nHelper::getLocale();
        $ds     =   & new Datasource_sql();
        $sql    =   array(
            'cols'      =>  "career_id, auto_suggest_code",
            'from'      =>  "$this->_table",
            'where'     => 'disable = 0',
            'orderby'   => 'auto_suggest_code'
        );
        $ds->setup($this->_db, $sql);
        return $ds->toArray();
    }
	
	public function deleteCareer($id) {
		$sql = "delete from $this->_table where $this->_key = $id";
		$this->_execute($sql);
	}
	
	public function disableCareer($id) {
		$sql = "update $this->_table set disable = 1 where $this->_key = $id";
		$this->_execute($sql);
		return ($this->disable);
	}
	
	//TODO: add a new function -- ntmdung
	public function enableCareer($id){
		$sql = "UPDATE $this->_table SET disable = 0 WHERE $this->_key = $id";
		$this->_execute($sql);
		return ($this->disable);
	}
	
}
?>